package com.example.ljw.frescowallpaper.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.ljw.frescowallpaper.R;
import com.example.ljw.frescowallpaper.helper.SDCardHelper;
import com.example.ljw.frescowallpaper.utils.RecyclerViewAdapterHelper;
import com.example.ljw.frescowallpaper.view.Details;
import com.example.ljw.frescowallpaper.view.DownloadDetailsActivity;

import java.io.File;
import java.util.List;

/**
 * Created by Administrator on 2016/11/20 0020.
 */

public class MyDownloadAdapter extends RecyclerViewAdapterHelper<File>{

    public MyDownloadAdapter(Context context, List<File> list) {
        super(context, list);
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view=mInflater.inflate(R.layout.item_layout,parent,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {

        MyViewHolder myViewHolder = (MyViewHolder) holder;
        Glide.with(mContext)
                .load(mList.get(position))
                .placeholder(R.mipmap.wallpaper)
                .centerCrop()
                .into(myViewHolder.img);
    }

    class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        ImageView img;
        public MyViewHolder(View itemView) {
            super(itemView);
            img = (ImageView) itemView.findViewById(R.id.img_item);
            img.setOnClickListener(this);
        }

        @Override
        public void onClick(View view) {
            int size = mList.size();
            File path = new File(SDCardHelper.getSDCardPublicDir(Environment.DIRECTORY_DOWNLOADS));
            File[] files = path.listFiles();
            int length = files.length;
            int a = length - size;
            Intent intent =new Intent(mContext,DownloadDetailsActivity.class);
            intent.putExtra("position",getAdapterPosition()+a);
            mContext.startActivity(intent);

        }
    }
}
